home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 16 / IOPROG_16.ISO / soft / macaxsdk / macsdk.hqx / ActiveX DR3 SDK / ActiveX SDK / Container Common / Util.c / Util.c
Encoding:
Text File  |  1997-08-04  |  3.7 KB  |  178 lines  |  [TEXT/CWIE]

  1. // >>> ⌐ 1996-1997 Microsoft Corporation.  All rights reserved. <<<
  2. #define _MAC
  3. #include <ole2.h>
  4. #include <dispatch.h>
  5. #include "Util.h"
  6.  
  7. Handle FileURLFromFileSpec (FSSpec* FileSpec)
  8. {
  9.     CInfoPBRec    myPB;            // parameter block for PBGetCatInfo
  10.     Str255        dirName;        // a directory name
  11.     OSErr        myErr;
  12.     Int32        NameLen = 0;
  13.     Int32        PathLen = 256;
  14.     Handle        tempPathHdl = NewHandleClear(256);
  15.     char*        tempPath;
  16.     char        FileURL[16] = "file:///";
  17.     Int16        move;
  18.  
  19.     if(tempPathHdl == NULL)
  20.         return NULL;
  21.     
  22.     HLock(tempPathHdl);
  23.     tempPath = *tempPathHdl;
  24.         
  25.     tempPath[0] = 0;                // initialize full pathname}
  26.     myPB.hFileInfo.ioNamePtr = &dirName[0];
  27.     myPB.hFileInfo.ioVRefNum = FileSpec->vRefNum;    // indicate target volume
  28.     myPB.dirInfo.ioDrParID = FileSpec->parID;      // initialize parent directory ID
  29.     myPB.dirInfo.ioFDirIndex = -1;                    // get info about a directory
  30.  
  31.     p2cstr(FileSpec->name);
  32.     strcat(tempPath, (char*)FileSpec->name);
  33.     c2pstr((char*)FileSpec->name);
  34.     NameLen = strlen(tempPath);
  35.     // Get name of each parent directory, up to root directory.
  36.     do
  37.     {
  38.         myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID;
  39.         myErr = PBGetCatInfoSync(&myPB);
  40.         p2cstr(dirName);
  41.         
  42.         // make sur string is long enough
  43.         while((strlen((char*)dirName) + NameLen) > (PathLen + 2))    // room for name, colon and termintating 0
  44.         {
  45.             PathLen += 256;
  46.             HUnlock(tempPathHdl);
  47.             SetHandleSize(tempPathHdl, PathLen);
  48.             if(tempPathHdl == NULL)
  49.                 return NULL;
  50.                 
  51.             HLock(tempPathHdl);
  52.             tempPath = *tempPathHdl;
  53.             
  54.         }
  55.         move = strlen((char*)dirName) + 1;
  56.         
  57.         // move existing string to make room for new folder name and ":"
  58.         BlockMove(tempPath, (char*)&tempPath[move], NameLen);
  59.         strcat((char*)dirName, "/");
  60.         move = strlen((char*)dirName);
  61.         BlockMove(dirName, tempPath, move);
  62.         NameLen += strlen((char*)dirName);
  63.     }
  64.     while( myPB.dirInfo.ioDrDirID != fsRtDirID);
  65.     
  66.     // add the file URL prefix
  67.     move = strlen((char*) FileURL);
  68.     
  69.     if ( (NameLen + move) > GetHandleSize(tempPathHdl) )
  70.     {
  71.         HUnlock(tempPathHdl);
  72.         SetHandleSize(tempPathHdl, GetHandleSize(tempPathHdl) + 256);
  73.         if(tempPathHdl == NULL)
  74.             return NULL;
  75.         HLock(tempPathHdl);
  76.         tempPath = *tempPathHdl;
  77.     }
  78.     
  79.     // move existing string to make room for new folder name and ":"
  80.     BlockMove(tempPath, (char*)&tempPath[move], NameLen);
  81.     BlockMove(FileURL, tempPath, move);
  82.     
  83.     HUnlock(tempPathHdl);
  84.     
  85.     return tempPathHdl;
  86. }
  87.  
  88.  
  89. void VarTypeToName(VARTYPE Type, Str255 TypeStr)
  90. {
  91.     switch ( Type )
  92.     {
  93.         case VT_EMPTY:
  94.             CopyPString(TypeStr, "\pvoid");
  95.             break;
  96.             
  97.         case VT_BSTR:
  98.             CopyPString(TypeStr, "\pString");
  99.             break;
  100.             
  101.         case VT_BOOL:
  102.             CopyPString(TypeStr, "\pBoolean");
  103.             break;
  104.             
  105.         case VT_ERROR:
  106.             CopyPString(TypeStr, "\pAXErrorCode");
  107.             break;
  108.             
  109.         case VT_I2:
  110.             CopyPString(TypeStr, "\pInt16");
  111.             break;
  112.             
  113.         case VT_UI2:
  114.             CopyPString(TypeStr, "\pUint16");
  115.             break;
  116.             
  117.         case VT_I4:
  118.             CopyPString(TypeStr, "\pInt32");
  119.             break;
  120.             
  121.         case VT_UI4:
  122.             CopyPString(TypeStr, "\pUint32");
  123.             break;
  124.             
  125.         case VT_R4:
  126.             CopyPString(TypeStr, "\pReal32");
  127.             break;
  128.             
  129.         case VT_R8:
  130.             CopyPString(TypeStr, "\pReal64");
  131.             break;
  132.             
  133.         case VT_INT:
  134.             CopyPString(TypeStr, "\pINT");
  135.             break;
  136.             
  137.         case VT_UINT:
  138.             CopyPString(TypeStr, "\pUINT");
  139.             break;
  140.             
  141.         case 14:
  142.             CopyPString(TypeStr, "\pFixed");
  143.             break;
  144.             
  145.         case VT_I1:
  146.             CopyPString(TypeStr, "\pChar8");
  147.             break;
  148.             
  149.         case VT_UI1:
  150.             CopyPString(TypeStr, "\pUchar8");
  151.             break;
  152.             
  153.         case VT_DATE:
  154.             CopyPString(TypeStr, "\pDate");
  155.             break;
  156.             
  157.         case VT_UNKNOWN:
  158.             CopyPString(TypeStr, "\pIUnknown*");
  159.             break;
  160.             
  161.         case VT_DISPATCH:
  162.             CopyPString(TypeStr, "\pIDispatch*");
  163.             break;
  164.             
  165.         default:
  166.             CopyPString(TypeStr, "\p-");
  167.             break;
  168.     }
  169. }
  170.  
  171.  
  172. void CopyPString(StringPtr DestStr, StringPtr SourceStr)
  173. {
  174.     BlockMove(SourceStr, DestStr, SourceStr[0]+1);
  175. }
  176.  
  177.  
  178.